package com.hjt.gulimall.product.config;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author:97007
 * @date:2021/9/28 11:53
 */
@Configuration
@EnableConfigurationProperties(ThreadPoolConfigProperties.class)
public class MyThreadConfig {

    @Bean
    public ThreadPoolExecutor executor(ThreadPoolConfigProperties properties){
        return  new org.apache.tomcat.util.threads.ThreadPoolExecutor(properties.getCoreSize(),
                                                                      properties.getMaxSize(),
                                                                      properties.getKeepAliveTime(),
                                                                      TimeUnit.SECONDS,
                                                                      new LinkedBlockingQueue<>(),
                                                                      Executors.defaultThreadFactory(),
                                                                      new ThreadPoolExecutor.AbortPolicy());
    }
}
